package com.lysj.merchant.material.controller;

import com.lysj.admin.utils.spring.foundation.base.BaseContent;
import com.lysj.merchant.desk.controller.DeskController;
import com.lysj.merchant.material.util.ImageByteUtil;
import com.lysj.merchant.material.util.ZipCompressorByAnt;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

/**
 * @ Author ：drj.
 * @ Date  ：Created in 14:45 2019/3/27
 * @ Description:
 **/
@RestController
@Slf4j
@RequestMapping("/merchant/material")
public class MaterilController extends BaseContent {

    private String filePath = DeskController.class.getResource("/").getPath().split("WEB-INF")[0] + "upload/";


    @GetMapping("/download")
    public void material(String storeId) {
        //打包文件的存放路径
        ZipCompressorByAnt zc = new ZipCompressorByAnt(filePath + "/file.zip");
        //需要打包的文件路径
        zc.compress("C:\\desk\\" + storeId + "\\waterMark\\");
        String contentType = "application/octet-stream";
        try {
            //导出压缩包
            ImageByteUtil.download(request, response, "upload/file.zip", contentType, ImageByteUtil.encodeChineseDownloadFileName(request, "file.zip"));
        } catch (Exception e) {
            request.getSession().setAttribute("msg", "暂无内容");
        }
        //如果原压缩包存在,则删除
        File file = new File(filePath + "/file.zip");
        if (file.exists()) {
            file.delete();
        }
    }
}
